package br.unb.mestrado.simulator.model.simulator;

import java.util.List;

import br.unb.mestrado.simulator.model.monitoring.State;
import br.unb.mestrado.simulator.model.simulator.formula.QualityFormula;
import br.unb.mestrado.simulator.model.spl.Feature;

public class QualityFormulaResult  {

	private Integer id;
	
	private ContextConfiguration context;
	
	private QualityFormula formula = null;
	private List<SplSpecification> splsNormal = null;
	private List<SplSpecification> splsModerate = null;
	private List<SplSpecification> splsHigh = null;
	private Boolean approved;
	private String type = null;
	
	
	
	public QualityFormulaResult(Integer id) {
		this.id = id;
	}

	public QualityFormulaResult(QualityFormula formula, ContextConfiguration context) {
		super();
		this.formula = formula;
		this.splsNormal = formula.getSpls().get(State.N);
		this.splsModerate = formula.getSpls().get(State.M);
		this.splsHigh = formula.getSpls().get(State.H);
		this.type = formula.getClass().getName();
		this.approved = formula.getApproved();
		this.context = context;
	}

	public QualityFormula getFormula() {
		return formula;
	}

	public void setFormula(QualityFormula formula) {
		this.formula = formula;
	}

	public List<SplSpecification> getSplsNormal() {
		return splsNormal;
	}

	public void setSplsNormal(List<SplSpecification> splsNormal) {
		this.splsNormal = splsNormal;
	}

	public List<SplSpecification> getSplsModerate() {
		return splsModerate;
	}

	public void setSplsModerate(List<SplSpecification> splsModerate) {
		this.splsModerate = splsModerate;
	}

	public List<SplSpecification> getSplsHigh() {
		return splsHigh;
	}

	public void setSplsHigh(List<SplSpecification> splsHigh) {
		this.splsHigh = splsHigh;
	}

	public Boolean getApproved() {
		return approved;
	}

	public void setApproved(Boolean approved) {
		this.approved = approved;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getSplsNormalDescription() {
		return getSplsSpecificationDescription(getSplsNormal());
	}
	
	public String getSplsModerateDescription() {
		return getSplsSpecificationDescription(getSplsModerate());
	}
	
	public String getSplsHighDescription() {
		return getSplsSpecificationDescription(getSplsHigh());
	}

	private String getSplsSpecificationDescription(List<SplSpecification> specifications) {
		StringBuilder sb = new StringBuilder();
		sb.append("conf{");
		if(specifications!=null){
			for (SplSpecification spc : specifications) {
				sb.append("\n");
				sb.append("qos={"+spc.getQuality()+"}, ");
				if(spc.getConfiguration().getFeatures()!=null){
					sb.append("features={");
					for(Feature feature: spc.getConfiguration().getFeatures()){
						sb.append(feature.getName()+";");
					}
					sb.append("}");
				}
			}
		}
		sb.append("}");
		return sb.toString();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public ContextConfiguration getContext() {
		return context;
	}

	public void setContext(ContextConfiguration context) {
		this.context = context;
	}
	
}
